import Immutable from 'immutable';

import { ADD_MAPINFO_REDUX, UPDATE_MAPINFO_REDUX } from './actionTypes';
import preloadedState from '../../preloadedState';

const defaultMapInfo = preloadedState.get('mapInfo');

function reducer (state = defaultMapInfo, action) {
    const { type, payload } = action;
    let newState = state;

    switch (type) {
        case ADD_MAPINFO_REDUX:
            return newState;
        case UPDATE_MAPINFO_REDUX:
            newState = newState.merge(Immutable.fromJS(payload));
            return newState;
        default:
            return state;
    }
}

export default reducer;